package com.hzyb.shopCommodity.controller;

import java.net.URLDecoder;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.hzyb.shopCommodity.service.ShopCommodityService;
import com.hzyb.shopContent.service.ShopContentService;
import com.hzyb.shopProductSpecifications.service.ShopProductSpecificationService;

@RestController
@RequestMapping("/ShopCommodity")
public class ShopCommodityController {


	private static final Logger Logger=org.slf4j.LoggerFactory.getLogger(ShopCommodityController.class);


	@Resource
	private ShopCommodityService shopCommodityService;

	@Resource
	private ShopProductSpecificationService ShopProductSpecificationService;

	@Resource
	private ShopContentService ShopContentService;

	@RequestMapping("/getShopCommodity")
	public Map<String, Object> getShopCommodity(@RequestParam String commoditySid) {
		Map<String, Object> map=new HashMap<>();
		try {
			map.put("productInformation", shopCommodityService.getShopCommodityById(commoditySid));
			map.put("type", ShopProductSpecificationService.getShopProductSpecificationsBycommoditySid(commoditySid));
			map.put("content",ShopContentService.getShopContentByCommoditySid(commoditySid));
			map.put("picList", shopCommodityService.getShopPic(commoditySid));
			map.put("status", "success");
		} catch (Exception e) {
			map.put("status", "fail");
			Logger.error(e.toString());
		}
		return map;
	}

	@RequestMapping("/queryShop")
	public Map<String, Object> queryShop(@RequestParam String keyWord){
		Map<String, Object> map=new HashMap<>();
		map.put("status", "fail");
		try {
			map.put("data", shopCommodityService.queryShop(URLDecoder.decode(keyWord,"UTF-8")));
			map.put("status", "success");
		} catch (Exception e) {
			Logger.error(e.toString());
		}
		return map;
	}

}
